package chu.dejian.dialogOrMenu;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Gravity;
import com.sam.blemodule.R;
import com.sam.dialog.CustomAlertDialogBuilder;
import com.sam.dialog.CustomDialog;
import com.sam.widget.text_view.IconTextView;

import chu.dejian.ui.activity.BLEMainActivity;

/**
 * Created by Administrator on 2016/6/19 0019.
 */
public class DialogManager {
    private static CustomAlertDialogBuilder networkErrorDialog;
    public static CustomAlertDialogBuilder getNetworkErrorDialog(Activity activity){
        IconTextView readyToMeasureView = new IconTextView(activity, R.drawable.ic_network_error,40,R.string.network_error);
        readyToMeasureView.setTextColor(activity.getResources().getColor(R.color.dark_gray_text_color));
        readyToMeasureView.setTextSize(18);
        if(networkErrorDialog == null) networkErrorDialog = new CustomAlertDialogBuilder.Builder(activity).setTitle(R.string.error)
                .setContentLayoutGravity(Gravity.CENTER)
                .setView(readyToMeasureView).create();
        return networkErrorDialog;
    }

    private static CustomDialog readyToMeasureDialog;
    public static CustomDialog getReadyToMeasureDialog(Activity activity){
        IconTextView readyToMeasureView = new IconTextView(activity, R.drawable.ic_waitforex,40,R.string.keep_at_level_of_heart);
        readyToMeasureView.setTextColor(activity.getResources().getColor(R.color.main_blue_color));
        readyToMeasureView.setTextSize(24);
        if(readyToMeasureDialog == null) readyToMeasureDialog = new CustomDialog(activity,readyToMeasureView);
        return readyToMeasureDialog;
    }

    private static CustomAlertDialogBuilder noNetworkMeasureOnlyDialog;
    public static CustomAlertDialogBuilder getNoNetworkMeasureOnlyDialog(final Activity activity){
        IconTextView readyToMeasureView = new IconTextView(activity, R.drawable.no_network,15,R.string.no_network_measure_only_tips);
        readyToMeasureView.setTextColor(activity.getResources().getColor(R.color.main_blue_color));
        readyToMeasureView.setTextSize(16);
        if(noNetworkMeasureOnlyDialog == null) noNetworkMeasureOnlyDialog = new CustomAlertDialogBuilder.Builder(activity)
                .setTitle(R.string.error).setContentLayoutGravity(Gravity.CENTER)
                .setView(readyToMeasureView).setNegativeButton(R.string.to_measure, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        activity.startActivity(new Intent(activity, BLEMainActivity.class));
                    }
                }).setPositiveButton(R.string.exit_app, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        activity.finish();
                    }
                }).create();
        return noNetworkMeasureOnlyDialog;
    }

    private static CustomAlertDialogBuilder notAllowedEnterDialog;
    public static CustomAlertDialogBuilder getNotAllowedEnterDialog(final Activity activity){
        IconTextView readyToMeasureView = new IconTextView(activity, R.drawable.no_network,15,R.string.not_allowed_enter_tips);
        readyToMeasureView.setTextColor(activity.getResources().getColor(R.color.main_blue_color));
        readyToMeasureView.setTextSize(16);
        if(notAllowedEnterDialog == null) notAllowedEnterDialog =  new CustomAlertDialogBuilder.Builder(activity)
                .setTitle(R.string.error).setContentLayoutGravity(Gravity.CENTER)
                .setPositiveButton(R.string.exit_app, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        activity.finish();
                    }
                }).create();
        return notAllowedEnterDialog;
    }

    private static CustomDialog measureErrorDialog;
    public static CustomDialog getMeasureErrorDialog(Activity activity,String errorStr){
        IconTextView readyToMeasureView = new IconTextView(activity, R.drawable.ic_linkeq_fail,40,errorStr);
        readyToMeasureView.setTextColor(activity.getResources().getColor(R.color.main_blue_color));
        readyToMeasureView.setTextSize(24);
        if(measureErrorDialog == null) measureErrorDialog =  new CustomDialog(activity,readyToMeasureView);
        readyToMeasureView.setText(errorStr);
        return measureErrorDialog;
    }

}
